home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / sox / auto.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  81 lines

  1. /*
  2.  * May 19, 1992
  3.  * Copyright 1992 Guido van Rossum And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Guido van Rossum And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. /*
  11.  * A meta-handler that recognizes most file types by looking in the
  12.  * first part of the file.  The file must be seekable!
  13.  * (IRCAM sound files are not recognized -- these don't seem to be
  14.  * used any more -- but this is just laziness on my part.) 
  15.  */
  16.  
  17. #include "st.h"
  18.  
  19. IMPORT void gettype();
  20.  
  21. autostartread(ft)
  22. ft_t ft;
  23. {
  24.     char *type;
  25.     char header[132];
  26.     if (!ft->seekable)
  27.         fail("Type AUTO input must be a file, not a pipe");
  28.     if (fread(header, 1, sizeof header, ft->fp) != sizeof header)
  29.         fail("Type AUTO detects short file");
  30.     fseek(ft->fp, 0L - sizeof header, 1); /* Seek back */
  31.     type = 0;
  32.     if (strncmp(header, ".snd", 4) == 0 ||
  33.         strncmp(header, "dns.", 4) == 0 ||
  34.         header[0] == '\0' && strncmp(header+1, "ds.", 3) == 0) {
  35.         type = "au";
  36.     }
  37.     else if (strncmp(header, "FORM", 4) == 0) {
  38.         if (strncmp(header + 8, "AIFF", 4) == 0)
  39.             type = "aiff";
  40.         else if (strncmp(header + 8, "8SVX", 4) == 0)
  41.             type = "8svx";
  42.     }
  43.     else if (strncmp(header, "RIFF", 4) == 0 &&
  44.          strncmp(header + 8, "WAVE", 4) == 0) {
  45.         type = "wav";
  46.     }
  47.     else if (strncmp(header, "Creative Voice File", 19) == 0) {
  48.         type = "voc";
  49.     }
  50.     else if (strncmp(header+65, "FSSD", 4) == 0 &&
  51.          strncmp(header+128, "HCOM", 4) == 0) {
  52.         type = "hcom";
  53.     }
  54.     else if (strncmp(header, "SOUND", 5) == 0) {
  55.         type = "sndt";
  56.     }
  57.     else if (header[0] == 0 && header[1] == 0) {
  58.         int rate = (header[2] & 0xff) + ((header[3] & 0xff) << 8);
  59.         if (rate >= 4000 && rate <= 25000)
  60.             type = "sndr";
  61.     }
  62.       if (type == 0) {
  63.           printf("Type AUTO doesn't recognize this header\n");
  64.                 printf("Trying: -t raw -r 11000 -b -u\n\n");
  65.                 type = "raw";
  66.                 ft->info.rate = 11000;
  67.                 ft->info.size = BYTE;
  68.                 ft->info.style = UNSIGNED;
  69.                 }
  70.     report("Type AUTO changed to %s", type);
  71.     ft->filetype = type;
  72.     gettype(ft); /* Change ft->h to the new format */
  73.     (* ft->h->startread)(ft);
  74. }
  75.  
  76. autostartwrite(ft) 
  77. ft_t ft;
  78. {
  79.     fail("Type AUTO can only be used for input!");
  80. }
  81.